// @before-stub-for-debug-begin
#include <vector>
#include <string>
#include "commoncppproblem173.h"

using namespace std;
// @before-stub-for-debug-end

/*
 * @lc app=leetcode.cn id=173 lang=cpp
 *
 * [173] 二叉搜索树迭代器
 */

// @lc code=start
/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     TreeNode *left;
 *     TreeNode *right;
 *     TreeNode() : val(0), left(nullptr), right(nullptr) {}
 *     TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
 *     TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
 * };
 */
class BSTIterator {
private:
    vector<TreeNode*> Tree;
    int it;
public:
    TreeNode* BST(TreeNode *root)
    {
        if(root == NULL)
            return NULL;
        BST(root->left);
        Tree.push_back(root);
        BST(root->right);
        return root;
    }

    BSTIterator(TreeNode* root) {
        BST(root);
        it = 0;
    }
    
    int next() {
        return Tree[it++]->val;
        
    }
    
    bool hasNext() {
        if(it == Tree.size())
            return false;
        else
            return true;
    }
};

/**
 * Your BSTIterator object will be instantiated and called as such:
 * BSTIterator* obj = new BSTIterator(root);
 * int param_1 = obj->next();
 * bool param_2 = obj->hasNext();
 */
// @lc code=end

